package com.xiaor.rssmodel.model;

import com.xiaor.rssmodel.model.common.Common;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.*;
import java.util.List;

/**
 * 历史事件具体地区
 */
@Entity
@Table(name = "area")
@Data   //生成Getter和Setter
@NoArgsConstructor  //生成无参构造函数
@AllArgsConstructor //生成有参构造函数
public class Area extends Common {
    @Column(columnDefinition = "varchar(20) comment '地区名'", unique = true)
    private String name;
    @Column(columnDefinition = "varchar(255) comment '简介'", unique = true)
    private String introduction;
    @Column(columnDefinition = "double comment '经度'", unique = true)
    private Double longitude;
    @Column(columnDefinition = "double comment '纬度'", unique = true)
    private Double latitude;
    @ManyToOne
    @JoinTable(name = "province_area",
            joinColumns = {@JoinColumn(name = "aid")},
            inverseJoinColumns = {@JoinColumn(name = "pid")}
    )
    private Province province;
    @OneToMany
    @JoinTable(name = "area_image",
            joinColumns = {@JoinColumn(name = "aid")},
            inverseJoinColumns = {@JoinColumn(name = "mid")}
    )
    private List<Image> imageList;
    @ManyToMany
    @JoinTable(name = "area_event",
            joinColumns = {@JoinColumn(name = "aid")},
            inverseJoinColumns = {@JoinColumn(name = "eid")}
    )
    private List<Event> eventList;
    @ManyToMany
    @JoinTable(name = "area_figure",
            joinColumns = {@JoinColumn(name = "aid")},
            inverseJoinColumns = {@JoinColumn(name = "fid")}
    )
    private List<Figure> figureList;

    @Override
    public String toString() {
        return "Area{" +
                "name='" + name + '\'' +
                ", introduction='" + introduction + '\'' +
                ", longitude=" + longitude +
                ", latitude=" + latitude +
                '}';
    }
}
